package com.itboye.ihomebank.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.bean.HouseListBean.HouseItem;
import com.itboye.ihomebank.constants.NetPublicConstant;
import com.itboye.ihomebank.custom.FlowLayout;
import com.itboye.ihomebank.net.NetPublicParams;
import com.itboye.ihomebank.support.commonadapter.MutiplyCommonAdapter;
import com.itboye.ihomebank.support.commonadapter.ViewHolder;
import com.itboye.ihomebank.util.XImageLoader;

/**
 * 首页的搜索
 * 
 */
public class SouSuoAdapter extends MutiplyCommonAdapter<HouseItem> {

	List<HouseItem> datas;

	public SouSuoAdapter(Context context, List<HouseItem> datas,
			int... layoutId) {
		super(context, datas, layoutId);
		this.datas = datas;
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void getItemPosition(int position) {
		// TODO Auto-generated method stub

	}

	@SuppressLint("ResourceAsColor")
	@Override
	public void convert(ViewHolder holder, HouseItem t, int type, int position) {
		// TODO Auto-generated method stub
		
		XImageLoader.load(NetPublicConstant.IMAGE_URL+t.getMainImg(),
				(ImageView) holder.getView(R.id.item_sou_img));
		holder.setText(R.id.item_sou_title, t.getTitle());
		StringBuffer jianjie = new StringBuffer();
		if (t.getHouseRoom() != null) {
			jianjie.append(t.getHouseRoom() + "室");
		}
		if (t.getHouseHall() != null) {
			jianjie.append(t.getHouseHall() + "厅");
		}
		if (t.getToilet() != null) {
			jianjie.append(t.getToilet() + "卫/");
		}
		if (t.getOritation() != null) {
			jianjie.append(t.getOritation() + "/");
		}
		if (t.getAreaNone() != null) {
			jianjie.append(t.getAreaNone());
		}
		FlowLayout flowLayout = (FlowLayout) holder.getView(R.id.flowLayout);
		flowLayout.removeAllViews();
		if (t.getTagNames() != null) {
			String[] other = t.getTagNames().split(",");
			for (int i = 0; i < other.length; i++) {
				View view = LayoutInflater.from(mContext).inflate(
						R.layout.item_other, null);
				android.widget.RelativeLayout.LayoutParams lP = new android.widget.RelativeLayout.LayoutParams(
						android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,
						android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
				TextView textView = (TextView) view.findViewById(R.id.text);
				textView.setTextColor(mContext.getResources().getColor(
						R.color.black));
				lP.setMargins(0, 2, 2, 2);
				textView.setText(other[i]);
				flowLayout.addView(view, lP);
			}
		}
		holder.setText(R.id.item_sou_content, jianjie + "");

		holder.setText(R.id.item_sou_money, t.getRent() + "元/月");
	}

}
